package com.cwj.thread;

/**
 * setDaemon(true)方法使当
 */
public class DaemonTest {
    public static void main(String[] args) {
        Thread t1 = new Thread() {
            @Override public void run() {
                Thread t2 = new Thread() {
                    @Override public void run() {
                        try {
                            Thread.sleep(3_000L);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        System.out.println("t2");
                    }
                };
                t2.setDaemon(true);
                t2.start();
                try {
                    Thread.sleep(1_000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t1");
            }
        };
        t1.setDaemon(true);
        t1.start();

        try {
            Thread.sleep(2_000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("main");
        System.out.println(Thread.currentThread().getId());
    }
}
